package edu.unindra.company.gui;

import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

import com.toedter.calendar.JDateChooser;

import usu.widget.ButtonGlass;
import usu.widget.Panel;
import usu.widget.glass.TextBoxGlass;
import edu.unindra.company.template.ViewPortGlass;

import java.awt.Color;
import java.awt.Font;
import java.awt.Dimension;

public class FormMainEmployeeAdd extends Panel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JLabel jLblNim;
	private JLabel jLblTmptLahir;
	private JLabel jLblTglLahir;
	private JLabel jLblJenisKelamin;
	private JLabel jLblJabatan;
	private JLabel jLblPhoto;
	private JLabel jLblNama;
	private JLabel jLblKontak;
	private JLabel jLblAlamat;
	private JLabel jLblTitle;
	private JLabel jLblMasaKerja;

	private JTextArea txtAlamat;

	private ButtonGlass btnSubmit;
	private ButtonGlass btnCancel;
	private ButtonGlass btnReset;

	private TextBoxGlass txtId;
	private TextBoxGlass txtName;
	private TextBoxGlass txtContact;
	private TextBoxGlass txtTmptLahir;
	private TextBoxGlass txtJabatan;
	private TextBoxGlass txtMasaKerja;
	private TextBoxGlass txtPhoto;

	private JScrollPane jScrollPanel;
	private ViewPortGlass view;

	@SuppressWarnings("rawtypes")
	private JComboBox cbJenisKelamin;
	private JDateChooser dcTglLahir;

	private String invalidMessage = "";

	public String[] listJnsKelamin = { "L", "P" };

	public FormMainEmployeeAdd() {
		initComponents();
	}

	public String getInvalidMessage() {
		return invalidMessage;
	}

	public ButtonGlass getBtnSubmit() {
		return btnSubmit;
	}

	public ButtonGlass getBtnCancel() {
		return btnCancel;
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	private void initComponents() {
		jScrollPanel = new JScrollPane();
		view = new ViewPortGlass();

		jLblNim = new JLabel();
		jLblTmptLahir = new JLabel();
		jLblTglLahir = new JLabel();
		jLblJenisKelamin = new JLabel();
		jLblJabatan = new JLabel();
		jLblPhoto = new JLabel();
		jLblNama = new JLabel();
		jLblKontak = new JLabel();
		jLblAlamat = new JLabel();
		jLblTitle = new JLabel();
		jLblMasaKerja = new JLabel();

		txtAlamat = new JTextArea();

		txtId = new TextBoxGlass();
		txtName = new TextBoxGlass();
		txtContact = new TextBoxGlass();
		txtTmptLahir = new TextBoxGlass();
		txtJabatan = new TextBoxGlass();
		txtMasaKerja = new TextBoxGlass();
		txtPhoto = new TextBoxGlass();

		cbJenisKelamin = new JComboBox();
		cbJenisKelamin.setModel(new javax.swing.DefaultComboBoxModel(
				listJnsKelamin));
		cbJenisKelamin.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
		cbJenisKelamin.setLightWeightPopupEnabled(false);

		dcTglLahir = new JDateChooser();
		dcTglLahir.getSpinner().setForeground(Color.BLACK);
		dcTglLahir.setFont(new java.awt.Font("Tahoma", 1, 11));

		btnSubmit = new ButtonGlass();
		btnSubmit.setFont(new Font("Tahoma", Font.BOLD, 11));
		btnSubmit.setGlassColor(Color.BLACK);
		btnCancel = new ButtonGlass();
		btnCancel.setFont(new Font("Tahoma", Font.BOLD, 11));
		btnCancel.setGlassColor(Color.BLACK);
		btnReset = new ButtonGlass();
		btnReset.setFont(new Font("Tahoma", Font.BOLD, 11));
		btnReset.setGlassColor(Color.BLACK);

		view.setView(txtAlamat);

		txtAlamat.setColumns(20);
		txtAlamat.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
		txtAlamat.setForeground(Color.BLACK);
		txtAlamat.setLineWrap(true);
		txtAlamat.setRows(5);
		txtAlamat.setWrapStyleWord(true);
		txtAlamat.setBorder(javax.swing.BorderFactory.createEmptyBorder(10, 10,
				10, 10));
		txtAlamat.setFocusAccelerator('A');
		txtAlamat.setOpaque(false);

		setBorder(javax.swing.BorderFactory.createLineBorder(
				new java.awt.Color(0, 0, 0), 3));
		setMinimumSize(new java.awt.Dimension(485, 339));
		setPreferredSize(new Dimension(485, 460));

		jLblNim.setFont(new java.awt.Font("Tahoma", 1, 11));
		jLblNim.setForeground(Color.BLACK);
		jLblNim.setText("Nim");

		jLblTmptLahir.setFont(new java.awt.Font("Tahoma", 1, 11));
		jLblTmptLahir.setForeground(Color.BLACK);
		jLblTmptLahir.setText("Tempat Lahir");

		jLblTglLahir.setFont(new java.awt.Font("Tahoma", 1, 11));
		jLblTglLahir.setForeground(Color.BLACK);
		jLblTglLahir.setText("Tgl Lahir");

		jLblJenisKelamin.setFont(new java.awt.Font("Tahoma", 1, 11));
		jLblJenisKelamin.setForeground(Color.BLACK);
		jLblJenisKelamin.setText("Jenis Kelamin");

		jLblJabatan.setFont(new java.awt.Font("Tahoma", 1, 11));
		jLblJabatan.setForeground(Color.BLACK);
		jLblJabatan.setText("Jabatan");

		jLblPhoto.setFont(new java.awt.Font("Tahoma", 1, 11));
		jLblPhoto.setForeground(Color.BLACK);
		jLblPhoto.setText("Photo");

		jLblNama.setFont(new java.awt.Font("Tahoma", 1, 11));
		jLblNama.setForeground(Color.BLACK);
		jLblNama.setText("Nama");

		jLblKontak.setFont(new java.awt.Font("Tahoma", 1, 11));
		jLblKontak.setForeground(Color.BLACK);
		jLblKontak.setText("Kontak");

		jLblAlamat.setFont(new java.awt.Font("Tahoma", 1, 11));
		jLblAlamat.setForeground(Color.BLACK);
		jLblAlamat.setText("Alamat");

		jLblMasaKerja.setFont(new java.awt.Font("Tahoma", 1, 11));
		jLblMasaKerja.setForeground(Color.BLACK);
		jLblMasaKerja.setText("Masa Kerja");

		jScrollPanel.setBorder(javax.swing.BorderFactory
				.createLineBorder(new java.awt.Color(0, 0, 0)));
		jScrollPanel.setOpaque(false);
		jScrollPanel.setViewport(view);

		btnSubmit.setMnemonic('T');
		btnSubmit.setText("Tambah");
		btnSubmit.setRoundRect(true);

		btnReset.setMnemonic('R');
		btnReset.setText("Reset");
		btnReset.setRoundRect(true);
		btnReset.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				buttonResetActionPerformed(evt);
			}
		});

		btnCancel.setMnemonic('B');
		btnCancel.setText("Batal");
		btnCancel.setRoundRect(true);

		jLblTitle.setFont(new java.awt.Font("Tahoma", 1, 24));
		jLblTitle.setForeground(Color.BLACK);
		jLblTitle.setText("Tambah Employee Baru");

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
		this.setLayout(layout);
		layout.setHorizontalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addContainerGap()
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING)
												.addGroup(
														javax.swing.GroupLayout.Alignment.TRAILING,
														layout.createSequentialGroup()
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.LEADING,
																				false)
																				.addComponent(
																						jLblPhoto,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						Short.MAX_VALUE)
																				.addComponent(
																						jLblAlamat,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						65,
																						Short.MAX_VALUE)
																				.addComponent(
																						jLblKontak,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						Short.MAX_VALUE)
																				.addComponent(
																						jLblMasaKerja,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						Short.MAX_VALUE)
																				.addComponent(
																						jLblJabatan,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						Short.MAX_VALUE)
																				.addComponent(
																						jLblJenisKelamin,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						Short.MAX_VALUE)
																				.addComponent(
																						jLblTglLahir,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						Short.MAX_VALUE)
																				.addComponent(
																						jLblTmptLahir,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						Short.MAX_VALUE)
																				.addComponent(
																						jLblNama,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						Short.MAX_VALUE)

																				.addComponent(
																						jLblNim))
																.addPreferredGap(
																		javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.LEADING)
																				.addComponent(
																						jScrollPanel,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						390,
																						Short.MAX_VALUE)
																				.addComponent(
																						txtId,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						390,
																						Short.MAX_VALUE)
																				.addComponent(
																						txtName,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						390,
																						Short.MAX_VALUE)
																				.addComponent(
																						txtTmptLahir,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						390,
																						Short.MAX_VALUE)
																				.addComponent(
																						dcTglLahir,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						390,
																						Short.MAX_VALUE)
																				.addComponent(
																						cbJenisKelamin,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						390,
																						Short.MAX_VALUE)
																				.addComponent(
																						txtJabatan,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						390,
																						Short.MAX_VALUE)
																				.addComponent(
																						txtMasaKerja,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						390,
																						Short.MAX_VALUE)
																				.addComponent(
																						txtContact,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						390,
																						Short.MAX_VALUE)
																				.addComponent(
																						txtPhoto,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						390,
																						Short.MAX_VALUE)))
												.addGroup(
														javax.swing.GroupLayout.Alignment.TRAILING,
														layout.createSequentialGroup()
																.addComponent(
																		btnReset,
																		javax.swing.GroupLayout.PREFERRED_SIZE,
																		javax.swing.GroupLayout.DEFAULT_SIZE,
																		javax.swing.GroupLayout.PREFERRED_SIZE)
																.addPreferredGap(
																		javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																.addComponent(
																		btnCancel,
																		javax.swing.GroupLayout.PREFERRED_SIZE,
																		javax.swing.GroupLayout.DEFAULT_SIZE,
																		javax.swing.GroupLayout.PREFERRED_SIZE)
																.addPreferredGap(
																		javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																.addComponent(
																		btnSubmit,
																		javax.swing.GroupLayout.PREFERRED_SIZE,
																		javax.swing.GroupLayout.DEFAULT_SIZE,
																		javax.swing.GroupLayout.PREFERRED_SIZE))
												.addComponent(
														jLblTitle,
														javax.swing.GroupLayout.Alignment.TRAILING,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														459, Short.MAX_VALUE))
								.addContainerGap()));
		layout.setVerticalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addGap(11, 11, 11)
								.addComponent(jLblTitle)
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(jLblNim)
												.addComponent(
														txtId,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE))

								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(jLblNama)
												.addComponent(
														txtName,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(jLblTmptLahir)
												.addComponent(
														txtTmptLahir,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(jLblTglLahir)
												.addComponent(
														dcTglLahir,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(jLblJenisKelamin)
												.addComponent(
														cbJenisKelamin,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(jLblJabatan)
												.addComponent(
														txtJabatan,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(jLblMasaKerja)
												.addComponent(
														txtMasaKerja,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(jLblKontak)
												.addComponent(
														txtContact,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(jLblPhoto)
												.addComponent(
														txtPhoto,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING)
												.addComponent(
														jScrollPanel,
														javax.swing.GroupLayout.Alignment.TRAILING,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														92, Short.MAX_VALUE)
												.addComponent(jLblAlamat))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(
														btnSubmit,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE)
												.addComponent(
														btnReset,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE)
												.addComponent(
														btnCancel,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addContainerGap()));

		setVisible(true);
	}

	private void buttonResetActionPerformed(java.awt.event.ActionEvent evt) {
		reset();
	}

	/**
	 * reset all text component
	 */
	public void reset() {
		txtId.setText("");
		txtName.setText("");
		txtTmptLahir.setText("");
		cbJenisKelamin.setSelectedIndex(0);
		txtJabatan.setText("");
		txtMasaKerja.setText("");
		txtPhoto.setText("");
		txtAlamat.setText("");
		txtContact.setText("");

	}

	public boolean isDataKarywanValid() {
		if (txtId.getText().trim().equalsIgnoreCase("")) {
			invalidMessage = "Nim karyawan masih kosong";
			return false;
		}

		if (txtName.getText().trim().equalsIgnoreCase("")) {
			invalidMessage = "Nama karyawan masih kosong";
			return false;
		}

		if (txtTmptLahir.getText().equalsIgnoreCase("")) {
			invalidMessage = "Tempat lahir masih kosong";
			return false;
		}

		if (txtContact.getText().trim().equalsIgnoreCase("")) {
			invalidMessage = "No kontak masih kosong";
			return false;
		}

		if (txtAlamat.getText().trim().equalsIgnoreCase("")) {
			invalidMessage = "Alamat masih kosong";
			return false;
		}

		if (txtJabatan.getText().trim().equalsIgnoreCase("")) {
			invalidMessage = "Jabatan masih kosong";
			return false;
		}

		if (txtMasaKerja.getText().trim().equalsIgnoreCase("")) {
			invalidMessage = "Masa kerja masih kosong";
			return false;
		}
		return true;

	}
}
